
//% color="#6699FF" iconWidth=50 iconHeight=40
namespace emw3080 {
    //% block="Wi-Fi连接到 [wifi_ssid] [wifi_password]" blockType="command"
    //% wifi_ssid.shadow="string" wifi_ssid.defl=your_ssid
    //% wifi_password.shadow="string" wifi_password.defl=your_password
    export function wifiConnect(parameter: any) {
        let _wifi_ssid = parameter.wifi_ssid.code;
        let _wifi_password = parameter.wifi_password.code;
        Generator.addInclude('EMW3080', '#include <EMW3080.h>');
        // Generator.addObject(`wifi_ssid`, `const char*`, `wifi_ssid=${_wifi_ssid}`);
        // Generator.addObject(`wifi_password`, `const char*`, `wifi_password=${_wifi_password}`);
        Generator.addCode(`while(1) {\n\t\tif (!WiFi_init(${_wifi_ssid}, ${_wifi_password}))continue;\n\t\tbreak;\n\t}`);
    }

    //% block="连接到阿里云MQTT [ProductKey] [DeviceName] [password]" blockType="command"
    //% ProductKey.shadow="string" ProductKey.defl=your_ProductKey
    //% DeviceName.shadow="string" DeviceName.defl=your_DeviceName
    //% password.shadow="string" password.defl=your_password
    export function AliyunConnect(parameter: any) {
        let _ProductKey = parameter.ProductKey.code;
        let _DeviceName = parameter.DeviceName.code;
        let _password = parameter.password.code;
        Generator.addInclude('EMW3080', '#include <EMW3080.h>');
        // Generator.addObject(`ProductKey`, `const char*`, `ProductKey=${_ProductKey}`);
        // Generator.addObject(`DeviceName`, `const char*`, `DeviceName=${_DeviceName}`);
        // Generator.addObject(`password`, `const char*`, `password=${_password}`);
        Generator.addCode(`while(1) {\n\t\tif (!Ali_connect(${_ProductKey}, ${_DeviceName}, ${_password}))continue;\n\t\tbreak;\n\t}`);
    }

    //% block="使用主题 [pubTopic] 发布 [JSON_DATA_PACK]" blockType="command"
    //% pubTopic.shadow="string" pubTopic.defl=your_pubtopic
    //% JSON_DATA_PACK.shadow="string" JSON_DATA_PACK.defl=your_message
    export function Set_pubTopic(parameter: any) {
        let _pubTopic = parameter.pubTopic.code;
        let _JSON_DATA = parameter.JSON_DATA_PACK.code;

        Generator.addInclude('EMW3080', '#include <EMW3080.h>');
        // Generator.addObject(`pubTopic`, `const char*`, `AT_pubTopic=${AT_pubTopic}`);
        // Generator.addObject(`MQTT_DATA`, `const char*`, `JSON_DATA_PACK=${_MQTT_DATA}`);
        Generator.addCode(`Upload(${_pubTopic}, ${_JSON_DATA});`);
    }

}
